package us.luosl.lslt.common;

import java.util.List;

public class Page<T> {

    private List<T> data;
    private Integer pageSize;
    private Integer currentPage;
    private Integer totalCount;
    private Integer totalPage;
    private Boolean hasNextPage;

    public Page(List<T> data, Integer pageSize, Integer currentPage, Integer totalCount) {
        this.data = data;
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.totalCount = totalCount;
        this.totalPage = calcTotalPage();
        this.hasNextPage = calcHasNextPage();
    }

    private Integer calcTotalPage() {
        int mod = getTotalCount() % getPageSize();
        int totalPage = getTotalCount() / getPageSize();
        if(mod != 0){
            totalPage += 1;
        }
        return totalPage;
    }

    private boolean calcHasNextPage() {
        return getCurrentPage() < getTotalPage();
    }

    public List<T> getData() {
        return data;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public Boolean getHasNextPage() {
        return hasNextPage;
    }

    public Boolean isEmpty(){
        return getData().size() == 0;
    }
}
